package com.oracle.lingshangejia.activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.base.BaseActivity;

public class ChangeInformationActivity extends BaseActivity implements View.OnClickListener {

    private InputMethodManager manager;
    private RelativeLayout re_back;
    private TextView tv_title,tv_sub_title;
    private EditText ed_content;

    @Override
    public int intiLayout() {
        return R.layout.activity_change_information;
    }

    @Override
    public void initView() {

        manager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        re_back = findViewById(R.id.re_back);
        re_back.setOnClickListener(this);
        tv_title = findViewById(R.id.tv_title);
        tv_sub_title = findViewById(R.id.tv_sub_title);
        ed_content = findViewById(R.id.ed_content);
    }

    @Override
    public void initData() {

        if (getIntent().getStringExtra("type").equals("0")){

            //修改姓名
            tv_title.setText("修改姓名");
            tv_sub_title.setText("姓名");
            ed_content.setHint("请输入新姓名");
            ed_content.setInputType(InputType.TYPE_CLASS_TEXT);
        }else if (getIntent().getStringExtra("type").equals("1")){

            //修改身份证号
            tv_title.setText("修改身份证号");
            tv_sub_title.setText("身份证号");
            ed_content.setHint("请输入新身份证号");
        }else if (getIntent().getStringExtra("type").equals("2")){

            //修改工作单位
            tv_title.setText("修改工作单位");
            tv_sub_title.setText("工作单位");
            ed_content.setHint("请输入新工作单位");
            ed_content.setInputType(InputType.TYPE_CLASS_TEXT);
        }else if (getIntent().getStringExtra("type").equals("3")){

            //修改本人电话
            tv_title.setText("修改本人电话");
            tv_sub_title.setText("本人电话");
            ed_content.setHint("请输入新本人电话");
            ed_content.setInputType(InputType.TYPE_CLASS_NUMBER);
        }
    }

    @Override
    public void onClick(View v) {

        if(getCurrentFocus()!=null && getCurrentFocus().getWindowToken()!=null){
            manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }

        switch (v.getId()){

            //返回键
            case R.id.re_back:

                finish();
                break;
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        if (event.getAction() == MotionEvent.ACTION_DOWN){

            if(getCurrentFocus()!=null && getCurrentFocus().getWindowToken()!=null){
                manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
        return super.onTouchEvent(event);
    }
}
